package com.xiaoge.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaoge.annotation.ControllerEndpoint;
import com.xiaoge.entity.CourseCategory;
import com.xiaoge.entity.WebsiteLink;
import com.xiaoge.response.Result;
import com.xiaoge.service.CourseCategoryService;
import com.xiaoge.vo.CourseCategoryVO;
import com.xiaoge.vo.MenuNodeVO;
import com.xiaoge.vo.WebsiteLinkVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 课程分类 前端控制器
 * </p>
 *
 * @author XiaoGe
 * @since 2022-10-28
 */

@Api("课程分类")
@RestController
@RequestMapping("/courseCategory")
public class CourseCategoryController {

    @Autowired
    private CourseCategoryService courseCategoryService;



    /**
     * 加载菜单树
     *
     * @return
     */
    @ApiOperation(value = "加载课程分类菜单树", notes = "获取课程分类所有菜单树，以及展开项")
    @GetMapping("/tree")
    public Result tree(@RequestParam(value = "categoryName",required = true,defaultValue = "") String categoryName) {

        List<CourseCategory> menuTree = courseCategoryService.findMenuTree(categoryName);

        return Result.ok().data("munuTree",menuTree);
    }


//    /**
//     * 模糊+条件获取友情链接信息
//     * @param categoryName
//     * @return
//     */
//    @ApiOperation("模糊+条件获取课程信息")
//    @GetMapping("/getCourseCategoryList")
//    public Result getCourseCategoryList(@RequestParam(value = "categoryName",required = true) String categoryName){
//
//        List<CourseCategory>  list = courseCategoryService.getCourseCategoryListLike(categoryName);
//
//        System.out.println(list.size());
//
//        return Result.ok().data("list",list);
//    }

    @ApiOperation(tags = "课程",value = "编辑课程信息")
    @GetMapping("/editCategory")
    public Result editCategory(@RequestParam("id") String id){
        CourseCategory category = courseCategoryService.editCategory(id);
        return Result.ok().data("editCategory",category);
    }

    @ApiOperation(tags = "课程",value = "修改课程信息")
    @ControllerEndpoint(exceptionMessage = "修改课程失败", operation = "修改课程")
    @PutMapping("/updateCategory")
    public Result updateCategory(@RequestBody CourseCategoryVO courseCategoryVO){
        int i = courseCategoryService.updateCategory(courseCategoryVO);
        return Result.ok().data("updateCategory",i);
    }

    @PostMapping("/addNav")
    @ApiOperation(tags = "导航栏",value = "增加导航信息")
    @ControllerEndpoint(exceptionMessage = "增加导航失败", operation = "增加导航")
    public Result addNav(@RequestBody  CourseCategoryVO courseCategoryVO){
        System.err.println(courseCategoryVO);
        int i = courseCategoryService.addNav(courseCategoryVO);
        return Result.ok().data("addNav",i);
    }

    @PostMapping("/updateStatus")
    @RequiresPermissions({"navigation:status"})
    @ControllerEndpoint(exceptionMessage = "更新课程状态失败", operation = "更新课程状态")
    @ApiOperation(tags = "导航栏",value = "修改课程状态")
    public Result updateStatus(String id,Integer status){
        int i = courseCategoryService.updateStatus(id, status);
        return Result.ok().data("updateStatus",i);
    }


    /**
     * 删除用户
     *
     * @param id 用户ID
     * @return
     */
    @ApiOperation(value = "删除课程信息", notes = "删除课程信息，根据用户ID")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        courseCategoryService.removeById(id);
        return Result.ok();
    }












}
